﻿Imports System.Data.OleDb
Public Class createProfile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionStringList").ConnectionString)
            Dim sqlString As String = "SELECT * FROM UserProfile WHERE TechieName = @f1"

            Dim cmd As New OleDbCommand(sqlString, oleDbConn)
            oleDbConn.Open()
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@f1", User.Identity.Name)

            Dim dr As OleDbDataReader = cmd.ExecuteReader()
            If dr.HasRows Then
                dr.Read()

                If Not IsDBNull(dr("Title")) Then ddl_Gender.SelectedValue = dr("Title")

                If Not IsDBNull(dr("FName")) Then tb_Fname.Text = dr("Fname")

                If Not IsDBNull(dr("LName")) Then tb_Lname.Text = dr("Lname")

                If Not IsDBNull(dr("Gender")) Then ddl_Gender.SelectedValue = dr("Gender")

                If Not IsDBNull(dr("TelNumber")) Then tb_contact.Text = dr("TelNumber")

                If Not IsDBNull(dr("OwnedCell")) Then rbl_CellModel.SelectedValue = dr("OwnedCell")

                If Not IsDBNull(dr("Network")) Then rbl_Network.SelectedValue = dr("Network")
            End If
            oleDbConn.Close()
        End If
    End Sub

   
    Protected Sub Btn_Submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Btn_Submit.Click
        Dim sqlString1 As String
        If Fup_UserImage.HasFile Then
            Fup_UserImage.SaveAs(Request.MapPath("Pictures") & "/" & Fup_UserImage.FileName)
        End If
        Dim oleDbConn1 As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionStringList").ConnectionString)
        If Fup_UserImage.HasFile Then
            sqlString1 = "UPDATE UserProfile SET Picture = @f1,Title = @f2,FName=@f3,Lname=@f4,Gender=@f5,TelNumber=@f6,OwnedCell=@f7,Network=@f8 WHERE TechieName = @f9"
        Else
            sqlString1 = "UPDATE UserProfile SET Title = @f2,FName=@f3,Lname=@f4,Gender=@f5,TelNumber=@f6,OwnedCell=@f7,Network=@f8 WHERE TechieName = @f9"
        End If


        Dim cmd2 As New OleDbCommand(sqlString1, oleDbConn1)
        oleDbConn1.Open()
        cmd2.CommandType = CommandType.Text

        cmd2.Parameters.AddWithValue("@f1", "Pictures/" & Fup_UserImage.FileName)
        cmd2.Parameters.AddWithValue("@f2", ddl_Title.SelectedValue.ToString())
        cmd2.Parameters.AddWithValue("@f3", tb_Fname.Text)
        cmd2.Parameters.AddWithValue("@f4", tb_Lname.Text)
        cmd2.Parameters.AddWithValue("@f5", ddl_Gender.SelectedValue.ToString())
        cmd2.Parameters.AddWithValue("@f6", tb_contact.Text)
        cmd2.Parameters.AddWithValue("@f7", rbl_CellModel.SelectedValue.ToString())
        cmd2.Parameters.AddWithValue("@f8", rbl_Network.SelectedValue.ToString())
        cmd2.Parameters.AddWithValue("@f9", User.Identity.Name)
        cmd2.ExecuteNonQuery()
        cmd2.Dispose()

        oleDbConn1.Close()
        oleDbConn1.Dispose()

        MsgBox("Your profile has been updated.Click OK", MsgBoxStyle.OkOnly, "Profile Update")
        Response.Redirect("TechieProfile.aspx?TechieName=" & User.Identity.Name)
    End Sub
End Class